package wicket.example.components.table;

import java.io.Serializable;
import java.util.List;

import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.Model;

public class DataViewWithColumns<T extends Serializable> extends DataView<T>
{

   private static final long          serialVersionUID = 1L;

   List<? extends DataTableColumn<T>> columns          = null;

   public DataViewWithColumns(String id, List<? extends DataTableColumn<T>> columns, IDataProvider<T> dataProvider, long itemsPerPage)
   {
      super(id, dataProvider, itemsPerPage);
      this.columns = columns;
   }

   @Override
   protected void populateItem(Item<T> item)
   {
      T modelObject = item.getModelObject();
      for (DataTableColumn<T> column : columns)
      {
         item.add(column.getComponent(Model.of(modelObject)));
      }
   }

}
